<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { computed, ref } from 'vue';
import { showFailToast, showToast } from '../../utils';
import { pickupTask } from '../../apis/task';


const taskId = ref('')
  onLoad(params => {
    taskId.value = params.id
  })
  const receiptImg = ref([])
  const goodsImg = ref([])
  const isSubmit = computed(() => {
    return receiptImg.value.length > 0 && goodsImg.value.length > 0
  })

  const submitImg = () => {
    if(receiptImg.value.length === 0 || goodsImg.value.length === 0){
      return showFailToast('请选择图片')
    }
    let req = {
      id:taskId.value,
      cargoPickUpPictureList:receiptImg.value.map(({url}) => {
        return {url}
      }),
      cargoPictureList:goodsImg.value.map(({url}) => {
        return {url}
      })
    }
    console.log('请求体',req);
    pickupTask(req,res => {
      console.log('上传结果',res);
      if(res.code === 200){
        showToast('上传成功','success')
        uni.navigateBack()
      }else{
        showFailToast(res.msg)
      }
    })
  }

</script>
<template>
  <view class="page-container">
    <view class="receipt-info">
      <uni-file-picker file-mediatype="image"
      file-extname="jpg,png,jpeg,webp,gif"
        v-model="receiptImg"
        limit="3" title="请拍照上传回单凭证"></uni-file-picker>
      <uni-file-picker file-mediatype="image"
      file-extname="jpg,png,jpeg,webp,gif"
        v-model="goodsImg"
        limit="3" title="请拍照上传货品照片"></uni-file-picker>
    </view>
    <button :disabled="!isSubmit" class="button" @click="submitImg">提交</button>
  </view>
</template>

<style lang="scss" scoped>
  .page-container {
    padding: 30rpx;
  }

  .receipt-info {
    min-height: 600rpx;
    background-color: #fff;
    padding: 20rpx 30rpx;
    border-radius: 16rpx;

    ::v-deep .uni-file-picker {
      margin-bottom: 30rpx;
    }
  }

  .button {
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    /* #ifdef APP */
    padding-top: 4rpx;
    /* #endif */
    border-radius: 100rpx;
    margin-top: 60rpx;
    color: #fff;
    font-size: $uni-font-size-big;
    background-color: $uni-primary;

    &[disabled],
    &.disabled {
      color: #fff;
      background-color: #fadcd9;
    }
  }
</style>
